<?php
App::uses('AppModel', 'Model');
class Menus extends AppModel {

	public $name = 'Menus';
	public $useTable = 'menus_multi';


	/**
	 * Get category
	 *
	 * @param string $cat_type
	 * @throws NotFoundException
	 * @return mixed
	 */
	public function getListMenu() {
		try{
			$results = $this->query(
					"SELECT id, mnu_name, mnu_order, mnu_link, mnu_target, mnu_parent_id
					FROM menus_multi
					WHERE mnu_active = 1
					ORDER BY mnu_parent_id ASC, mnu_order ASC
					");
			return  $results;
		} catch (Exception $e) {
			throw new NotFoundException(__('Invalid category'));
		}

	}
	/**
	 * Get level Menu parent
	 * @param number $id
	 * @return number $cat_level
	 */
	public function getLevelMenuParent($id = null){
		$query = array(
				'conditions' => array(
					'id' => $id,
					'mnu_active' => 1
				),
				'fields' => 'mnu_level, mnu_has_child',
		);
		try{
			$cat_parent = $this->find('first', $query);
			return $cat_parent['Menus']['mnu_level'];

		} catch (Exception $e) {
			throw new NotFoundException(__('Invalid Menu'));
		}
	}

}